]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Complex Components/MapRender/MapRenderView.swift
Address the lint warnings
[rbdr/map] / Map / Presentation / Complex Components / MapRender / MapRenderView.swift
1 // Copyright (C) 2024 Rubén Beltrán del Río
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see https://map.tranquil.systems.
15 import Combine
16 import CoreData
17 import CoreGraphics
18 import SwiftUI
19
20 struct MapRenderView: View {
21
22 @Binding var document: MapDocument
23 @Binding var evolution: StageType
24
25 var stage: Stage {
26 Stage.stages(evolution)
27 }
28
29 var parsedMap: ParsedMap {
30 MapParser.parse(content: document.text)
31 }
32
33 let mapSize = Dimensions.mapSize
34 let padding = Dimensions.mapPadding
35
36 let lineWidth = CGFloat(0.5)
37 let vertexSize = CGSize(width: 25.0, height: 25.0)
38
39 var onDragVertex: (Vertex, CGFloat, CGFloat) -> Void = { _, _, _ in }
40
41 var body: some View {
42 ZStack(alignment: .topLeading) {
43
44 Path { path in
45 path.addRect(
46 CGRect(
47 x: -padding, y: -padding, width: mapSize.width + padding * 2,
48 height: mapSize.height + padding * 4))
49 }.fill(.white)
50
51 MapStages(mapSize: mapSize, lineWidth: lineWidth, stages: parsedMap.stages)
52 MapAxes(
53 mapSize: mapSize, lineWidth: lineWidth, evolution: stage, stages: parsedMap.stages)
54 MapEdges(
55 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize, edges: parsedMap.edges)
56 MapBlockers(mapSize: mapSize, vertexSize: vertexSize, blockers: parsedMap.blockers)
57 MapVertices(
58 mapSize: mapSize, vertexSize: vertexSize, vertices: parsedMap.vertices,
59 onDragVertex: onDragVertex)
60 MapOpportunities(
61 mapSize: mapSize, lineWidth: lineWidth, vertexSize: vertexSize,
62 opportunities: parsedMap.opportunities)
63 MapGroups(mapSize: mapSize, vertexSize: vertexSize, groups: parsedMap.groups).drawingGroup(
64 opaque: true
65 ).opacity(0.1)
66 MapNotes(
67 mapSize: mapSize, lineWidth: lineWidth, notes: parsedMap.notes)
68 }.offset(x: padding, y: padding).frame(
69 width: mapSize.width + 2 * padding,
70 height: mapSize.height + 2 * padding, alignment: .topLeading
71 )
72 }
73 }
74
75 #Preview {
76 MapRenderView(
77 document: Binding.constant(MapDocument(text: "")),
78 evolution: Binding.constant(StageType.general)
79 )
80 }